package service

import (
	"gin/common"
	"gin/model"
	"github.com/go-ego/gpy"
	"strings"
)

func CreateScene(data model.Scene) (model.Scene, error) {
	if data.Code == "" {
		data.Code = strings.Join(gpy.LazyConvert(data.Name, nil), "")
	}
	err := model.Insert(&data)
	return data, err
}

func FindScene(Param common.SelectQueryParam) (resData model.Scene, err error) {
	var logModel model.Scene
	err = model.Find(&logModel, Param.Filter.Filter, nil)
	return logModel, err
}

func SelectScene(Param *common.SelectQueryParam) (total int64, resData []model.Scene, err error) {
	var logModel model.Scene

	total, resData, err = logModel.Select(Param)

	return
}

func UpdateScene(Data model.Scene) (model.Scene, error) {
	return Data.Update(Data)
}

func DeleteScene(param *common.Filter) {
	var logModel model.Scene
	logModel.DeleteByFilter(param)
	return
}
